package com.sk.weichat.util;

import android.text.TextUtils;

import com.sk.weichat.bean.Friend;
import com.sk.weichat.bean.NewContactsBean;
import com.sk.weichat.bean.RoomMember;
import com.sk.weichat.sortlist.BaseSortModel;

import java.util.List;

public class ListUtil {

    /**
     * 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置
     */
    public static int getPositionForSection(List<BaseSortModel<Friend>> mSortFriends, int section) {
        for (int i = 0; i < mSortFriends.size(); i++) {
            String sortStr = mSortFriends.get(i).getFirstLetter();
            char firstChar = sortStr.toUpperCase().charAt(0);
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }



    public static String getFirstStr(List<BaseSortModel<Friend>> mSortFriends, int position) {
        if (mSortFriends != null && mSortFriends.size() > 0) {
            if (!TextUtils.isEmpty(mSortFriends.get(position).getFirstLetter())) {
                return mSortFriends.get(position).getFirstLetter();
            } else {
                return "";
            }
        }
        return "";
    }

    public static int getSortContactssPositionForSection(List<BaseSortModel<NewContactsBean>> mSortContactss, int section) {
        for (int i = 0; i < mSortContactss.size(); i++) {
            String sortStr = mSortContactss.get(i).getFirstLetter();
            char firstChar = sortStr.toUpperCase().charAt(0);
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }


    public static String getFirstContactsStr(List<BaseSortModel<NewContactsBean>> mSortFriends, int position) {
        if (mSortFriends != null && mSortFriends.size() > 0) {
            if (!TextUtils.isEmpty(mSortFriends.get(position).getFirstLetter())) {
                return mSortFriends.get(position).getFirstLetter();
            } else {
                return "";
            }
        }
        return "";
    }

    public static String getFirstmRoomMembersStr(List<BaseSortModel<RoomMember>> mRoomMembers, int position) {
        if (mRoomMembers != null && mRoomMembers.size() > 0) {
            if (!TextUtils.isEmpty(mRoomMembers.get(position).getFirstLetter())) {
                return mRoomMembers.get(position).getFirstLetter();
            } else {
                return "";
            }
        }
        return "";
    }
    public static int getSortRoomMembersPositionForSection(List<BaseSortModel<RoomMember>> mRoomMember, int section) {
        for (int i = 0; i < mRoomMember.size(); i++) {
            String sortStr = mRoomMember.get(i).getFirstLetter();
            char firstChar = sortStr.toUpperCase().charAt(0);
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }


    /**
     * 根据ListView的当前位置获取分类的首字母的Char ascii值
     */
    public static int getSectionForPosition(List<BaseSortModel<Friend>> mSortFriends, int position) {
        return mSortFriends.get(position).getFirstLetter().charAt(0);
    }

    public static int getSectionmRoomMemberForPosition(List<BaseSortModel<RoomMember>> mRoomMember, int position) {
        return mRoomMember.get(position).getFirstLetter().charAt(0);
    }
    //判断list是否为空
    public static boolean isListEmpty(List list){
        if (list == null || list.size() < 1){
            return true;
        }
        return false;
    }

}
